export const tex = (data) => {
	const token = uni.getStorageSync("token")
	return new Promise((resolve, reject) => {
		uni.request({
			url: `/stream/v1/asr?appkey=S9S6dvzB5PaFSCpA&format=MP3`,
			method: "POST",
			header: {
				"Content-type": "application/octet-stream",
				"X-NLS-Token": token
			},
			data: data,
			success: (res) => {
				resolve(res)
			},
			fail: (error) => {
				reject(error)
			}
		})
	})

}

export const mp3 = (data) => {
	const token = uni.getStorageSync("token")
	return new Promise((resolve, reject) => {
		uni.request({
			url: `/stream/v1/tts?appkey=S9S6dvzB5PaFSCpA&token=${token}&text=${data}&format=mp3&sample_rate=16000`,
			method: "POST",
			header: {
				"X-NLS-Token": token
			},
			responseType: "arraybuffer",
			success: (res) => {

				resolve(res)
			},
			fail: (error) => {

				console.error('请求失败:', error)
				reject(error)
			}
		})

	})
}